using System;
using System.Collections.Generic;
using System.Text;
using Utility;
using DAL;
using DTO;
namespace BUS
{
   public class tbSanPhamBUS
    {
       public static void Insert(tbSanPham sanpham)
        {
            tbSanPhamDAL spDAL = new tbSanPhamDAL();
            spDAL.Insert(sanpham);
        }
       public static void Update(tbSanPham sanpham)
        {
            tbSanPhamDAL spDAl = new tbSanPhamDAL();
            spDAl.Update(sanpham);
        }
       public static void UpdateTT(tbSanPham sanpham)
       {
           tbSanPhamDAL spDAL = new tbSanPhamDAL();
           spDAL.UpdateTT(sanpham);
       }
        public static void Delete(int iD)
        {
            tbSanPhamDAL spDAl = new tbSanPhamDAL();
            spDAl.Delete(iD);
        }
       public static tbSanPhamCollection Get(string where, int pageindex, int pagesize, string orderby, string orderdirection, out int total)
        {
            tbSanPhamDAL spDAL = new tbSanPhamDAL();
            return spDAL.Get(where, pageindex, pagesize, orderby, orderdirection, out total);
        }
       public static tbSanPhamCollection GetAll()
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbSanPhamDAL spDAL = new tbSanPhamDAL();
            return spDAL.Get(cri.Criter, 0, 0, tbSanPhamColumns.masp.ToString(), OrderDirection.ASC.ToString(), out total);
        }
       public static tbSanPham GetByID(int iD)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, tbSanPhamColumns.masp.ToString(), Condition.EQUAL, iD);
            tbSanPhamDAL spDAL = new tbSanPhamDAL();
            tbSanPhamCollection spCollection = spDAL.Get(cri.Criter, 0, 0, tbSanPhamColumns.masp.ToString(), OrderDirection.ASC.ToString(), out total);
            if (spCollection.Count > 0)
                return spCollection[0];
            return null;
        }

       public static tbSanPham GetByMa(int iD)
       {
           int total = 0;
           Criteria cri = new Criteria();
           cri.add(Condition.AND, tbSanPhamColumns.doanhnghiep.ToString(), Condition.EQUAL, iD);
           tbSanPhamDAL spDAL = new tbSanPhamDAL();
           tbSanPhamCollection spCollection = spDAL.Get(cri.Criter, 0, 0, tbSanPhamColumns.doanhnghiep.ToString(), OrderDirection.ASC.ToString(), out total);
           if (spCollection.Count > 0)
               return spCollection[0];
           return null;
       }

       public static tbSanPham GetByMaSP(int Masp)
       {
           int t = 0;
           tbSanPhamDAL spmoi = new tbSanPhamDAL();
           tbSanPhamCollection danhsach = new tbSanPhamCollection();
           danhsach = spmoi.Get(" Where masp = " + "'" + Masp.ToString() + "'", 0, 0, tbSanPhamColumns.masp.ToString(), "ASC", out t);
           if (danhsach.Count == 1)

               return danhsach[0];
           return null;

       }

       public static void Update1(tbSanPham sp)
       {
           tbSanPhamDAL spDAl = new tbSanPhamDAL();
           spDAl.Update(sp);
       }
   }
    
}
